﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;

namespace VERKProjectHopur16.Models
{
    public class QAViewModel
    {
        /// <summary>
        /// This class is mocked for testing
        /// </summary>
        #region Repository interface variable
        IDataRepository m_rep = null;
        #endregion

        #region Constructors
        public QAViewModel()
        {
            m_rep = new DataRepository();

            Departments = new List<SelectListItem>();

            foreach(var dept in m_rep.GetAllDept())
            {
                Departments.Add(new SelectListItem { Text = dept.Name, Value = dept.DepartmentID.ToString( ) });
            }
            Departments.Add(new SelectListItem { Text = "-Select-", Value = "", Selected = true });
            InsertDate = DateTime.Now;
        }

        public QAViewModel(IDataRepository rep)
        {
            m_rep = rep;

            Departments = new List<SelectListItem>();

            foreach (var dept in m_rep.GetAllDept())
            {
                Departments.Add(new SelectListItem { Text = dept.Name, Value = dept.DepartmentID.ToString() });
            }
            Departments.Add(new SelectListItem { Text = "-Select-", Value = "", Selected = true });
            InsertDate = DateTime.Now;
        }
        #endregion

        #region Properties
        public int QAID { get; set; }

        [Required(ErrorMessage = "Field required")]
        public String Question { get; set; }

        public DateTime InsertDate { get; set; }

        [Required(ErrorMessage = "Field required")]
        public String DepartmentID { get; set; }

        [RegularExpression(@"^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$", ErrorMessage = "Invalid Email Address")] 
        public String CreatorEmail { get; set; }

        public List<SelectListItem> Departments { get; set; }
        #endregion
    }
}